package com.campol.activity;

import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.PreferenceActivity;

import com.campol.R;

public class SettingsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener {

	public static final String RADIUS_KEY = "radius";
	public static final String SEARCH_AREA_KEY = "search_area";
	private ListPreference radiusPreferences, searchAreaPreferences;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		addPreferencesFromResource(R.xml.pref_screen);
		getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
		
		radiusPreferences = (ListPreference) getPreferenceScreen().findPreference(RADIUS_KEY);
		searchAreaPreferences = (ListPreference) getPreferenceScreen().findPreference(SEARCH_AREA_KEY);
	}

	@Override
	public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
		if (RADIUS_KEY.equals(key)) {
			radiusPreferences.setSummary(radiusPreferences.getEntry());
		} else if (SEARCH_AREA_KEY.equals(key)) {
			searchAreaPreferences.setSummary(searchAreaPreferences.getEntry());
		}

	}
	
}
